<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
	<script type="text/javascript">
		$(document).ready(function() {
			show();
		});

		function show() {
			$.ajax({
				url : "/admin/sendindex",
				type : "post",
				dataType : "json",
				success : function(data) {
					var context = "";
					for (var i = 0; i < data.length; i++) {
						var po = data[i];
						context += '<tr id="trr' + i + '" ondblclick="de(' + i
								+ ')" onclick="getmesid(' + po.mesid + ')">'
								+ '<th width="15%"><font size="2">' + po.yname
								+ '</font></th>'
								+ '<th width="15%"><font size="2">' + po.cname
								+ '</font></th>'
								+ '<th width="55%"><font size="2">'
								+ po.describe + '</font></th>'
								+ '<th width="15%"><font size="2">' + po.state
								+ '</font></th>' + '</tr>'
					}
					$("#show_coachmes").html(context);
				}
			});
		}

		function sendtoindex(mesid) {
			$.ajax({
				url : "/admin/sendmestoindex",
				type : "post",
				data : {
					mesid : mesid
				},
				success : function(data) {
					alert(data);
					window.location.reload();
				}
			});
		}

		function notsendtoindex(mesid) {
			$.ajax({
				url : "/admin/notsendmes",
				type : "post",
				data : {
					mesid : mesid
				},
				success : function(data) {
					alert(data);
					window.location.reload();
				}
			});
		}

		function delmes(mesid) {
			$.ajax({
				url : "/admin/delectindexmes",
				type : "post",
				data : {
					mesid : mesid
				},
				success : function(data) {
					alert(data);
					window.location.reload();
				}
			});
		}

		function getmesid(mesid) {
			var put = "";
			put = '<button class="layui-btn" onclick="sendtoindex(' + mesid
					+ ')">推送消息</button>'
			$("#sendmes").html(put);
			var notput = "";
			notput = '<button  class="layui-btn" onclick="notsendtoindex('
					+ mesid + ')">取消推送</button>'
			$("#notsendmes").html(notput);
			var del = "";
			del = '<button class="layui-btn" onclick="delmes(' + mesid
					+ ')">删除该条推送</button>'
			$("#delmes").html(del);
		}

		function de(u) {
			for (var i = 0; i < 50; i++) {
				if ($("#trr" + i).css('background-color') === 'rgb(84, 255, 159)')
					$("#trr" + i).css('background-color', 'white');
			}
			$("#trr" + u).css('background-color', '#54FF9F');
		}
	</script>
	<div class="layui-card-body">
		<table class="layui-table">
			<tr>
				<th width="15%">场馆名</th>
				<th width="15%">教练名</th>
				<th width="55%">推送描述</th>
				<th width="15%">推送状态</th>
			</tr>

			<tbody id="show_coachmes">

			</tbody>
		</table>
	</div>

	<label for="L_repass" class="layui-form-label" id="sendmes">
		<button class="layui-btn">推送消息</button>
	</label>
	<label for="L_repass" class="layui-form-label" id="notsendmes"><button
			class="layui-btn">取消推送</button></label>


	<label for="L_repass" class="layui-form-label" id="delmes">
		<button class="layui-btn">删除该条推送</button>
	</label>

	<label for="L_repass" class="layui-form-label"></label>
	<label for="L_repass" class="layui-form-label">
		<button onclick="xadmin.open('新增推送','./addindexmes.html',600,500)"
			class="layui-btn">新增推送</button>
	</label>

</body>
</html>
